package practice_once_time;

import java.util.Scanner;

public class ChessBoard {
    int tile=1;//表示L型骨牌
    int[][] board=new int[100][100];
    public void chessBoard(int tr,int tc,int dr,int dc,int size){
        //           起始坐标 (tr,tc)   特殊方格坐标（dr,dc）  棋盘尺寸
        if (size==1){
            return;
        }
        int t=tile++;
        int s=size/2;

        //在左上角
        if (dr<tr+s && dc<tc+s){
            chessBoard(tr,tc,dr,dc,s);
        }else {
            board[tr+s-1][tc+s-1]=t;
            chessBoard(tr,tc,tr+s-1,tc+s-1,s);
        }

        //在右上角
        if (dr<tr+s&&dc>=tc+s){
            chessBoard(tr,tc+s,dr,dc,s);
        }else {
            board[tr+s-1][tc+s]=t;
            chessBoard(tr,tc+s,tr+s-1,tc+s,s);
        }

        //在左下角
        if (dr>=tr+s&&dc<tc+s){
            chessBoard(tr+s,tc,dr,dc,s);
        }else {
            board[tr+s][tc+s-1]=t;
            chessBoard(tr+s,tc,tr+s,tc+s-1,s);
        }

        //在右下角
        if (dr>=tr+s&&dc>=tc+s){
            chessBoard(tr+s,tc+s,dr,dc,s);
        }else {
            board[tr+s][tc+s]=t;
            chessBoard(tr+s,tc+s,tr+s,tc+s,s);
        }
    }

    public static void main(String[] args){
        ChessBoard chessBoard=new ChessBoard();
        Scanner sc =new Scanner(System.in);
        System.out.println("请输入棋盘大小（尺寸）");
        int size=sc.nextInt();
        System.out.println("请输入特殊方格的坐标");
        int dr=sc.nextInt();
        int dc=sc.nextInt();

        //棋盘覆盖
        chessBoard.chessBoard(0,0,dr,dc,size);

        for (int i=0;i<size;i++){
            for (int j=0;j<size;j++){
                System.out.print(String.format("%5d",chessBoard.board[i][j]));
            }
            System.out.println();
        }
    }
}
